﻿using FSLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSApp.BC
{
	/// <summary>
	/// フィルタのインスタンスをラップするItem.
	/// </summary>
	public class FilterItem : IComparable<FilterItem>
	{
		/// <summary>
		/// Filterのインスタンス
		/// </summary>
		public object Instance { get; private set; }

		/// <summary>
		/// Filter種別
		/// </summary>
		public FilterType FilterType { get; private set; }

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="ftype"></param>
		/// <param name="instance"></param>
		public FilterItem(FilterType ftype, object instance)
		{
			this.FilterType = ftype;
			this.Instance = instance;
		}

		/// <summary>
		/// ToStringのオーバーライド
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			string filterName = string.Empty;
			string filterDesc = string.Empty;

			// NOTE:フィルタの種別が増えたら、ここに追加
			// MEMO:色々なところでフィルタのInterfaceを意識する必要があるので、あまり良い実装では無い…。
			switch (this.FilterType)
			{
				case BC.FilterType.Filter2D:
					filterName = ((IFilter2D)this.Instance).FilterName;
					filterDesc = ((IFilter2D)this.Instance).Description;
					break;
				case BC.FilterType.Filter3D:
					filterName = ((IFilter3D)this.Instance).FilterName;
					filterDesc = ((IFilter3D)this.Instance).Description;
					break;
				case BC.FilterType.Analysis:
					filterName = ((IAnalysis)this.Instance).FilterName;
					filterDesc = ((IAnalysis)this.Instance).Description;
					break;
				default:
					return base.ToString();
			}

			return string.Format("{0} - {1} : {2}", this.FilterType.ToString(), filterName, filterDesc);

		}

		/// <summary>
		/// 比較
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		int IComparable<FilterItem>.CompareTo(FilterItem other)
		{
			// ToString()の比較結果を返す
			return this.ToString().CompareTo(other.ToString());
		}
	}
}
